<template>
  <el-checkbox
    v-model="localData"
    :true-value="trueValue"
    :false-value="falseValue"
    :disabled="disabled"
    :label="content"
    :border="border"
    @change="
      (v) => {
        change(v);
      }
    "
  />
</template>

<script>
export default {
  name: 'SingleCheckbox',
  // 不接收attrs，否则默认slot的attrs都会传递到这里（label和v-model），所以关闭了inheritAttrs
  inheritAttrs: false,
  props: {
    modelValue: {
      type: String,
      default: ''
    },
    trueValue: {
      type: String,
      default: 'Y'
    },
    falseValue: {
      type: String,
      default: 'N'
    },
    disabled: {
      type: Boolean,
      default: false
    },
    content: {
      type: String,
      default: ''
    },
    border: {
      type: Boolean,
      default: false
    },
    change: {
      type: Function,
      default: () => {}
    }
  },
  data() {
    return {
      localData: ''
    };
  },
  watch: {
    modelValue: {
      handler(newVal) {
        this.localData = String(newVal);
      },
      immediate: true
    },
    localData(newVal, oldVal) {
      this.$emit('update:modelValue', newVal);
    }
  }
};
</script>
